﻿namespace YZAutoDWR.Response;

public class ResponseContent
{
    public ResponseContent()
    {
    }

    public ResponseContent(bool status)
    {
        Status = status;
    }

    public bool Status { get; set; }
    public string? Code { get; set; }

    public string? Message { get; set; }

    public object? Data { get; set; }

    public ResponseContent OK()
    {
        Status = true;
        return this;
    }

    public static ResponseContent Instance => new();

    public ResponseContent OK(string message, object? data = null)
    {
        Status = true;
        Message = message;
        Data = data;
        return this;
    }

    public ResponseContent OK(ResponseType responseType)
    {
        return Set(responseType, true);
    }

    public ResponseContent Error(string? message = null)
    {
        Status = false;
        Message = message;
        return this;
    }

    public ResponseContent Error(ResponseType responseType)
    {
        return Set(responseType, false);
    }

    public ResponseContent Set(ResponseType responseType)
    {
        bool? b = null;
        return Set(responseType, b);
    }

    public ResponseContent Set(ResponseType responseType, bool? status)
    {
        return Set(responseType, null, status);
    }

    public ResponseContent Set(ResponseType responseType, string? msg)
    {
        bool? b = null;
        return Set(responseType, msg, b);
    }

    public ResponseContent Set(ResponseType responseType, string? msg, bool? status)
    {
        if (status != null)
        {
            Status = (bool)status;
        }

        Code = ((int)responseType).ToString();
        if (!string.IsNullOrEmpty(msg))
        {
            Message = msg;
            return this;
        }

        Message = responseType.GetMsg();
        return this;
    }
}